/* 批次记录
 * @Author: wujie 
 * @Date: 2018-06-12 11:06:36 
 * @Last Modified by: wujie
 * @Last Modified time: 2018-07-24 13:38:50
 */
import React,{ Component } from 'react'
import { Row } from 'antd'
import components from '@/components'
import { connect } from 'react-redux'
import actions from '@/actions/batchRecord'
import enumActions from '@/actions/enum'
import util from '@/utils'

const { BatchRecordSearch, BatchRecordTable, Card } = components

class BatchRecord extends Component {
  render(){

    const searchProps = util.pick(this.props,[
      'batchId', 
      'content',
      'status',
      'startTime', 
      'endTime',
      'auditBatchStatusEnum'
    ]) 

    const searchFunProps = util.pick(this,[
      'onChangeBatchId',
      'onChangeContent',
      'onChangeStatus',
      'onChangeStartTime',
      'onChangeEndTime',
      'onSearch',
    ])

    const tableProps = util.pick(this.props,[
      'pageNum', 
      'pageSize', 
      'auditBatchStatusEnum',
      'total', 
      'loading', 
      'data'
    ]) 

    return (
      <Card title="批次记录">
        <Row style={{ padding: '24px', backgroundColor: '#fff' }}>
          <BatchRecordSearch {...searchProps} {...searchFunProps} />
          <BatchRecordTable {...tableProps} onChangePagination={this.onChangePagination} />
        </Row>
      </Card>
    )
  }

  componentDidMount() {
    this.props.getAuditBatchStatusEnum()
    this.props.getData()
  }

  onChangeBatchId = ({target: { value }}) => {
    this.props.setBatchId(value)
  }

  onChangeContent = ({target: { value }}) => {
    this.props.setContent(value)
  }

  onChangeStatus = (value) => {
    this.props.setStatus(value)
  }
  
  onChangeStartTime = (value) => {
    this.props.setStartTime(value)
  }

  onChangeEndTime = (value) => {
    this.props.setEndTime(value)
  }

  onChangePagination = (pageNum) => {
    this.props.setPageNum(pageNum)
    this.props.getData()
  }

  onSearch = () => {
    this.props.setPageNum(1)
    this.props.getData()
  }
}

const mapStateToProps = ({ batchRecordReducer, enumReducer: { auditBatchStatusEnum } }) => ({ ...batchRecordReducer, auditBatchStatusEnum })

const mapDispatchToProps = { 
  ...actions,
  getAuditBatchStatusEnum: enumActions.getAuditBatchStatusEnum
}

export default connect(mapStateToProps, mapDispatchToProps)(BatchRecord)